home *** CD-ROM | disk | FTP | other *** search
/ Enigma Amiga Life 109 / EnigmaAmiga109CD.iso / dalla rivista / amiga.free / sorgenti vari / wolf3dmacsource.sit / Wolf3DMacSource / Wolf.ppc < prev    next >
Text File  |  1994-09-29  |  5KB  |  162 lines

  1. ;
  2. ; Assembly language functions for wolf 3-D PPC version
  3. ; Written by Bill Heineman
  4. ; 9-12-94 (Rev for removing scalers and using direct code)
  5. ;
  6.  
  7. ;
  8. ; Bullshit to make the PPC Mac environment know I'm here
  9. ;
  10.  
  11.      import VideoWidth        ; global variable from C program
  12.     import MacViewHeight
  13.     import ArtData
  14.     import VideoPointer
  15.     import ScaleDiv
  16.     
  17.     toc    
  18.     tc    VideoWidth[TC],VideoWidth
  19.     tc    MacViewHeight[TC],MacViewHeight
  20.     tc    ArtData[TC],ArtData
  21.     tc    VideoPointer[TC],VideoPointer
  22.     tc    ScaleDiv[TC],ScaleDiv
  23.     
  24.     export IO_ScaleWallColumn[DS]
  25.     export .IO_ScaleWallColumn[PR]
  26.     export SpriteGlue[DS]
  27.     export .SpriteGlue[PR]
  28.  
  29.     toc                ;Table of contents for the subroutines
  30.     tc IO_ScaleWallColumn[TC], IO_ScaleWallColumn[DS]
  31.     tc SpriteGlue[TC], SpriteGlue[DS]
  32.  
  33.     csect    IO_ScaleWallColumn[DS]
  34.     dc.l    .IO_ScaleWallColumn[PR]
  35.     dc.l    TOC[tc0]
  36.     
  37.     csect    SpriteGlue[DS]
  38.     dc.l    .SpriteGlue[PR]
  39.     dc.l    TOC[tc0]
  40.  
  41. ;
  42. ; This routine will draw a scaled wall column.
  43. ;
  44. ; void IO_ScaleWallColumn(Word x,Word scale,LongWord column)
  45. ;
  46.     
  47. WALLHEIGHT EQU 128+1
  48.  
  49. ; Passed from "C"
  50. X         equ R3        ;X coord
  51. Scale    equ    R4        ;Scale factor 
  52. Tile    equ    R5        ;Tile to draw 
  53. Column    equ    R6        ;Packed wall column #
  54. ; Locals
  55. ArtStart EQU R7        ;Pointer to wall art
  56. ScreenPtr EQU R8    ;Pointer to screen memory column
  57. Frac    EQU    R9        ;Fractional scaler
  58. Integer    EQU    R10        ;Fractional integer
  59. VWidth    EQU    R11        ;Video of the video screen in bytes
  60. Delta    EQU    R6        ;Delta factor and temp
  61. VHeight EQU R12        ;Height of mac screen
  62. Temp    EQU    R3        ;Temp (Use AFTER X is added)
  63.  
  64.     csect    .IO_ScaleWallColumn[PR]
  65.  
  66.     CMPLWI    Scale,0        ;Is the scale factor zero?
  67.     BEQLR                ;Exit NOW!
  68.     LWZ        ScreenPtr,VideoPointer[TC](RTOC)    ;Get handle to video
  69.     LWZ        ArtStart,ArtData[TC](RTOC)            ;Get handle to art data list
  70.     LWZ        VWidth,VideoWidth[TC](RTOC)            ;Get handle to video width
  71.     LWZ        Frac,ScaleDiv[TC](RTOC)
  72.     LWZ        VHeight,MacViewHeight[TC](RTOC)    ;Get pointer to view height
  73.     LWZ        ScreenPtr,0(ScreenPtr)                ;I have the base pointer 
  74.     LWZ        VWidth,0(VWidth)                    ;Init video width
  75.     LWZ        VHeight,0(VHeight)        ;Get the number of lines visible
  76.  
  77.     SLWI    Scale,Scale,1            ;Mul scale by 2 (Get true pixel value    
  78.     ADD        ScreenPtr,ScreenPtr,X    ;Add the X coord (Frees Temp)
  79.     SLWI    Temp,Scale,1            ;Get low word index
  80.     SLWI    Tile,Tile,2            ;Get the wall shape pointer
  81.     LWZX    Frac,Frac,Temp            ;Get the scale factor
  82.     SLWI    Column,Column,7            ;Mul by 128 pixels
  83.     LWZX    ArtStart,ArtStart,Tile    ;Get pointer to the shape 
  84.     ADD        ArtStart,ArtStart,Column    ;I have the shape ptr
  85.     CMPLW    Scale,VHeight            ;Too big?
  86.     BGE        ClipTop                ;Clip the top
  87.  
  88. ; No clipping needed!
  89. ; Adjust the dest screen for the starting Y coord
  90. ;
  91.  
  92.     MTCTR    Scale                ;Init counter
  93.     SUB        Temp,VHeight,Scale    ;How many lines to jump down?
  94.     LI        Delta,0                ;Init the delta factor
  95.     SRWI    Temp,Temp,1            ;Divide by to center vertically
  96.     SRWI    Integer,Frac,24        ;Isolate the integer
  97.     MULLW    Temp,VWidth,Temp    ;Adjust the Y coord
  98.     SLWI    Frac,Frac,8            ;Isolate the fraction
  99.     ADD        ScreenPtr,ScreenPtr,Temp    ;Create the dest screen pointer
  100.  
  101. ;
  102. ; Tight loop
  103. ; Grab byte, adjust fractional scaler values and store to screen
  104. ;
  105.  
  106. More:
  107.     LBZ        R0,0(ArtStart)        ;Fetch a shape byte
  108.     ADDC.    Delta,Delta,Frac    ;Add the scaler fractional
  109.     STB        R0,0(ScreenPtr)        ;Store on the screen
  110.     ADDE    ArtStart,ArtStart,Integer    ;Add the constant
  111.     ADD        ScreenPtr,ScreenPtr,VWidth    ;Go down a line 
  112.     BDNZ    More        ;All lines done?
  113.     BLR                    ;Exit routine
  114.  
  115. ;
  116. ; Clip the top and bottom
  117. ; Calc the number of lost lines by clipping and "Fake" 
  118. ; the numbers as if I processed those missing lines
  119. ;
  120.  
  121. ClipTop:
  122.     MTCTR    VHeight                ;I will draw a screen line full
  123.     SUB        Temp,Scale,VHeight    ;How many lines to jump down?
  124.     SRWI    Integer,Frac,24        ;Isolate the integer
  125.     SRWI    Temp,Temp,1            ;Divide by to center vertically
  126.     MULLW    Temp,Frac,Temp        ;Adjust the scaler by lost lines
  127.     SRWI    Delta,Temp,24        ;How many bytes are lost?
  128.     ADD        ArtStart,ArtStart,Delta    ;Create the SOURCE art pointer
  129.     SLWI    Frac,Frac,8            ;Isolate the fraction
  130.     SLWI    Delta,Temp,8        ;Init the adjusted delta
  131.     B        More                ;Jump to the code
  132.     
  133. ;
  134. ; Call the compiled scaler to draw a run of the line
  135. ;
  136.  
  137.  
  138.     csect    .SpriteGlue[PR]
  139.  
  140. SGArtStart    EQU    R3        ;Pointer to the 6 byte run structure
  141. SGFrac    EQU    R4        ;Pointer to the scaler
  142. SGInteger    EQU R5        ;Pointer to the video
  143. SGScreenPtr    EQU    R6        ;Pointer to the run base address
  144. SGCount    EQU R7
  145. SGDelta    EQU    R8
  146. SGVWidth    EQU    R9
  147.  
  148.     LWZ        SGVWidth,VideoWidth[TC](RTOC)
  149.     LWZ        SGVWidth,0(SGVWidth)
  150.     MTCTR    SGCount
  151.     
  152. SMore:
  153.     LBZ        R0,0(SGArtStart)        ;Fetch a shape byte
  154.     ADDC.    SGDelta,SGDelta,SGFrac    ;Add the scaler fractional
  155.     STB        R0,0(SGScreenPtr)        ;Store on the screen
  156.     ADDE    SGArtStart,SGArtStart,SGInteger    ;Add the constant
  157.     ADD        SGScreenPtr,SGScreenPtr,SGVWidth    ;Go down a line 
  158.     BDNZ    SMore        ;All lines done?
  159.     BLR                    ;Exit routine
  160.  
  161.